from utils.handler_util import HandlerUtil


class BaseHandlerHelper(object):
    def __init__(self, request, bll_cls, cls):
        self.request = request
        self.bll_cls = bll_cls
        self.cls = cls

    def _response(self, res):
        return self.request.write(HandlerUtil.set_response(message=res.message, code=200 if res.is_success else 400,
                                                           data=res.data))

    def _failure_response(self, message=""):
        return self.request.write(HandlerUtil.set_failure_response(message=message))

    @property
    def _get_conditions(self):
        return self.cls().add_edit_params if hasattr(self.cls, "add_edit_params") else []

    @property
    def _get_unique_fields(self):
        return self.cls().unique_fields if hasattr(self.cls, "unique_fields") else None
